package com.haoshuang.zhouzhoubang.ui.page.order.receiveorder

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.Home4Bean
import com.haoshuang.zhouzhoubang.model.bean.HomeBean
import com.haoshuang.zhouzhoubang.model.bean.Jnrz
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class ReceiveOrderListViewModel : BaseViewModel() {

    /**
     * 获取不感兴趣标签
     */
    val getUnlikeTagData = StatefulMutableLiveData<MutableList<String>>()
    fun getUnlikeTag() = netRequest {
        start { getUnlikeTagData.value = StateData.Loading }
        request { ApiRepo.getUnlikeTag() }
        success { getUnlikeTagData.value = StateData.Success(it.data) }
        error { code, msg ->
            getUnlikeTagData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取抢单任务列表
     */
    val getMasterTaskListData = StatefulMutableLiveData<MutableList<HomeBean>>()
    fun getMasterTaskList(page: Int) = netRequest {
        start { getMasterTaskListData.value = StateData.Loading }
        request { ApiRepo.getMasterTaskList(page) }
        success { getMasterTaskListData.value = StateData.Success(it.data) }
        error { code, msg ->
            getMasterTaskListData.value = StateData.Error(code, msg)
        }
    }

    
    /**
     * 提交不感兴趣数据
     */
    val addUnlikeOrderData = StatefulMutableLiveData<Any>()
    fun addUnlikeOrder(oid: String, unlike_tag: String, remark: String) = netRequest {
        start { addUnlikeOrderData.value = StateData.Loading }
        request { ApiRepo.add_unlike_order(oid, unlike_tag, remark) }
        success { addUnlikeOrderData.value = StateData.Success(it.data) }
        error { code, msg ->
            addUnlikeOrderData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 验证是否能接单
     */
    val verifyTakeTaskData = StatefulMutableLiveData<Any>()
    fun verifyTakeTask(orderId: String) = netRequest {
        start { verifyTakeTaskData.value = StateData.Loading }
        request { ApiRepo.verifyTakeTask(orderId) }
        success { verifyTakeTaskData.value = StateData.Success(it.data) }
        error { code, msg ->
            verifyTakeTaskData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 接单
     */
    val masterTakeTaskData = StatefulMutableLiveData<Home4Bean>()
    fun masterTakeTask(orderId: String) = netRequest {
        start { masterTakeTaskData.value = StateData.Loading }
        request { ApiRepo.masterTakeTask(orderId) }
        success { masterTakeTaskData.value = StateData.Success(it.data) }
        error { code, msg ->
            masterTakeTaskData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取抢单未认证技能信息
     */
    val masterGetSkillData = StatefulMutableLiveData<Jnrz>()
    fun masterGetSkill(orderId: String) = netRequest {
        start { masterGetSkillData.value = StateData.Loading }
        request { ApiRepo.masterGetSkill(orderId) }
        success { masterGetSkillData.value = StateData.Success(it.data) }
        error { code, msg ->
            masterGetSkillData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 去验证服务的时候调用接口
     */
    val verifyServiceData = StatefulMutableLiveData<Any>()
    fun verifyService(service_ids: String, little_ids: String) = netRequest {
        start { verifyServiceData.value = StateData.Loading }
        request { ApiRepo.verifyService(service_ids, little_ids) }
        success { verifyServiceData.value = StateData.Success(it.data) }
        error { code, msg ->
            verifyServiceData.value = StateData.Error(code, msg)
        }
    }
}